package scheduleManage

import (
	"hotel_Manager_Api/model/dbModel"
	"hotel_Manager_Api/util"
	"time"
)
type DeskStatus int
const (
	_ DeskStatus = iota
	Schedule
	Begin
	OrderFinish
	Cancle
)

type DeskOrderSchedule struct {
	DeskId      int64      `xorm:"deskId" json:"deskId,string"`
	Floor       int16      `xorm:"floor" json:"floor"`
	Name        string     `xorm:"name" json:"name"`
	ChairCount  int32      `xorm:"chairCount" json:"chairCount"`
	DeskOrderId *int64     `xorm:"deskOrderId" json:"deskOrderId,string"`
	DinnerTime  *time.Time `xorm:"dinnerTime" json:"dinnerTime"`
	OrderStatus *int32     `xorm:"orderStatus" json:"orderStatus"`
	BeginTime   *time.Time `xorm:"beginTime" json:"beginTime"`
	EndTime     *time.Time `xorm:"endTime" json:endTime`
}

type FoodOrder struct {
	FoodId int64 `json:"foodId,string"`
	Count  int32 `json:"count"`
}

type DeskOrderScheduleRequst struct {
	DeskId        int64 `json:"deskId,string"`
	HeadCount     int32 `json:"headCount"`
	OrderPhone    string `json:"orderPhone"`
	OrderUserName string `json:"orderUserName"`
	BeginTime     time.Time`json:"beginTime"`
	EndTime       time.Time`json:"endTime"`
	Remark        string`json:"remark"`
	Orders        []FoodOrder`json:"orders"`
	OrderUser     string`json:"orderUser"`
	OrderFrom     string`json:"orderFrom"`
}

func (self *DeskOrderScheduleRequst) toDbEntities(idGenerate util.IdGenerator) (DeskOrder, dbModel.ScheduleOrder, []dbModel.Order) {
	deskOrder := DeskOrder{
		Id:          idGenerate.GenerateNewId(),
		DinnerTime:  self.BeginTime,
		OrderStatus: Schedule,
		DeskId:      self.DeskId,
		CreateTime:  time.Now(),
	}

	scheduOrder := dbModel.ScheduleOrder{
		CreateTime:    time.Now(),
		BeginTime:     self.BeginTime,
		Id:            idGenerate.GenerateNewId(),
		DeskOrderId:   deskOrder.Id,
		EndTime:       self.EndTime,
		OrderFrom:     self.OrderFrom,
		OrderPhone:    self.OrderPhone,
		OrderUserName: self.OrderUserName,
		Remark:        self.Remark,
	}

	orders := make([]dbModel.Order, len(self.Orders))
	for i, item := range self.Orders {
		orders[i] = dbModel.Order{
			Id:          idGenerate.GenerateNewId(),
			DeskOrderId: deskOrder.Id,
			CreateTime:  time.Now(),
			Status:      dbModel.Create,
			Count:       item.Count,
			FoodId:      item.FoodId,
		}
	}
	return deskOrder, scheduOrder, orders
}
